//
//  DetailsCollectionViewCell.m
//  HimalayaMusic
//
//  Created by dllo on 16/1/7.
//  Copyright © 2016年 WXCLegendary. All rights reserved.
//

#import "DetailsCollectionViewCell.h"
#import "Masonry.h"
@implementation DetailsCollectionViewCell


- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        self.imageView1 = [[UIImageView alloc] init];
        [self addSubview:self.imageView1];
        
        
        self.imageView2 = [[UIImageView alloc] init];
        [self addSubview:self.imageView2];

        self.imageView3 = [[UIImageView alloc] init];
        [self addSubview:self.imageView3];


        self.imageView4 = [[UIImageView alloc] init];
        [self addSubview:self.imageView4];


        self.imageView5 = [[UIImageView alloc] init];
        [self addSubview:self.imageView5];
        self.imageView2.userInteractionEnabled = YES;
        self.imageView3.userInteractionEnabled = YES;
        self.imageView4.userInteractionEnabled = YES;
        self.imageView5.userInteractionEnabled = YES;
        self.imageView1.userInteractionEnabled = YES;

        
        UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        UITapGestureRecognizer *tap4 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
        UITapGestureRecognizer *tap5 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];

        [self.imageView1 addGestureRecognizer:tap1];
        [self.imageView2 addGestureRecognizer:tap2];
        
        [self.imageView3 addGestureRecognizer:tap3];
        [self.imageView4 addGestureRecognizer:tap4];
        [self.imageView5 addGestureRecognizer:tap5];
        
        self.imageView1.tag = 100;
        self.imageView2.tag = 101;
        self.imageView3.tag = 102;
        self.imageView4.tag = 103;
        self.imageView5.tag = 104;
        
    }
    return self;
    
}

//手势方法
- (void)tapAction:(UITapGestureRecognizer *)tap {

    
    switch (tap.view.tag) {
        case 100:
            self.block(@"3");
            break;
            
        case 101:
            self.block(@"2");
            break;
            
        case 102:
            self.block(@"4");
            break;
            
        case 103:
            self.block(@"12");
            break;
            
        case 104:
            
            self.block(@"6");
            break;
    }
    
    
    
    
//    NSLog(@"呵呵");
    
}




- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    
    CGFloat num = 10;
   [self.imageView1 mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.equalTo(self).offset(num);
       make.left.equalTo(self).offset(num);
       make.width.mas_equalTo(self.width/2);
       make.height.mas_equalTo(self.height);
       
       
       
   }];

    [self.imageView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(num);
        make.left.equalTo(self.imageView1.mas_right).offset(num);
        make.width.equalTo(self.imageView3);
        make.right.equalTo(self.imageView3.mas_left).offset(-num);
        make.height.mas_equalTo(self.height/2-5);
        
        
    }];
    
    [self.imageView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(num);
        make.left.equalTo(self.imageView2.mas_right).offset(num);
        make.width.equalTo(self.imageView2);
        make.right.equalTo(self.mas_right).offset(-num);
        make.height.equalTo(self.imageView2);
        
        
    }];
    
    [self.imageView4 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.imageView2.mas_bottom).offset(10);
        make.left.equalTo(self.imageView1.mas_right).offset(num);
        make.width.equalTo(self.imageView2);
        make.right.equalTo(self.imageView5.mas_left).offset(-num);
        make.height.equalTo(self.imageView2);
    }];
    
    [self.imageView5 mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.imageView3.mas_bottom).offset(10);
        make.left.equalTo(self.imageView4.mas_right).offset(num);
        make.right.equalTo(self.mas_right).offset(-num);
        make.height.equalTo(self.imageView4);
        
    }];
    
    
    
}


@end
